Skip to content

Conversation

@liga-oz
Copy link
Contributor

@liga-oz liga-oz commented Dec 20, 2023

No description provided.

@liga-oz liga-oz requested a review from finkmanAtSap December 20, 2023 09:09
}

private String composeZidQueryParameter(Token token) {
String composeQueryParameters(Token token) {
Copy link
Contributor

@finkmanAtSap finkmanAtSap Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about one of the following alternatives that, albeit not shorter, are probably more expressive / easier to maintain? Too much overhead?

String composeQueryParameters(Token token) {
        String query = 
                Map.of("zid", Objects.requireNonNullElse(token.getAppTid(), ""),
                        "client_id", Objects.requireNonNullElse(configuration.getClientId(), ""))
                .entrySet().stream()
                .filter(entry -> !entry.getValue().isBlank())
                .map(entry -> entry.getKey() + "=" + entry.getValue())
                .sorted()
                .collect(Collectors.joining("&", "?", ""));

        query = Objects.equals("?", query) ? "" : query;

        LOGGER.debug("Composed query parameter for token keys: {}", query);
        return query;
    }
String composeQueryParameters(Token token) {
        List<Map.Entry<String, String>> parameters = 
                Map.of("zid", Objects.requireNonNullElse(token.getAppTid(), ""),
                        "client_id", Objects.requireNonNullElse(configuration.getClientId(), ""))
                .entrySet().stream()
                .filter(entry -> !entry.getValue().isBlank())
                .collect(Collectors.toList());
        
        String query = parameters.isEmpty()
                ? ""
                : parameters.stream()
                .map(entry -> entry.getKey() + "=" + entry.getValue())
                .sorted()
                .collect(Collectors.joining("&", "?", ""));

        LOGGER.debug("Composed query parameter for token keys: {}", query);
        return query;
    }

private String composeZidQueryParameter(Token token) {
String composeQueryParameters(Token token) {
String zid = token.getAppTid();
String clientId = token.getClientId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be changed to

configuration.getClientId()

})
void composeQueryParams(String clientId, String appTid, String query) {
Token tokenMock = Mockito.mock(Token.class);
Mockito.when(tokenMock.getClientId()).thenReturn(clientId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this must be changed to

Mockito.when(mockConfiguration.getClientId()).thenReturn(clientId);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants